import Mock from 'mockjs'

const {contactsList } = Mock.mock({
    'contactsList|18': [
        {
            'proname|1': ['汇景园', '都会艺境', '新城北', '华策中心', '金茂府', '融信·澜天', '旭辉时代城', '中铁·逸都', '融创金成·未来海', '祥生·群贤府', '绿城·富春玫瑰园', '朗诗·熙华府', '融信·澜天', '越秀·亲爱里', '钱江彩虹府', '西房·拱宸外滩', '时间名座', '都城天漾·滨沁公寓'],
            location:'@city',
            "num|1-3":3,
            "nopress|1-3":1,
            'warning|1':['紧急','超标','保养'],
            'type|1':['自控','设备'],
            name: '@cname()',
            phone: /\d{11}/,
            detail:'@cparagraph(1)',
            'isnow|1':['https://img.axureshop.com/c9/57/1d/c9571de2aa7c47d2865ef6311a990b6a/images/%E7%BB%B4%E6%8A%A4%E6%89%98%E7%AE%A1/u4163.png','']
        },
    ],
})
Mock.mock('/api/contactsList', 'post', (config) => {

    return {
        code: 200,
        message: '获取数据成功',
        data: contactsList
    }
})
const {maskList } = Mock.mock({
    'maskList|18': [
        {
            'state|1':[ '这条任务已经逾期了','非常紧急的任务','一般紧急的任务','这是一条任务','分配给同伴的任务'],
            'time|1':['非常紧急','一般'],
            name:'@cname()',
            content:'@cparagraph(1)'
        }
    ],
})
Mock.mock('/api/maskList', 'post', (config) => {

    return {
        code: 200,
        message: '获取数据成功',
        data: maskList
    }
})
Mock.mock('/api/showmaskList', 'post', (config) => {
    const showmask=[]
    const res = {
        code: 200,
        message: '获取数据失败',
        data:showmask

    }
    for (let i = 0; i < maskList.length; i++) {
        showmask.push(maskList[i])
        res.message = '获取数据成功'
        if( showmask.length>=5){
            break
        }
    }
    
    return res
})
Mock.mock('/api/addmaskList', 'post', (config) => {
    const req = JSON.parse(config.body)
    const registerList=[{
        state:req.state,
        time:req.time,
        name:req.name,
        content:req.content
    }]
    maskList.push(registerList)
    const res = {
        code: 200,
        message: '获取数据失败',
        data: maskList

    }
  
    return res
})
const {talkList } = Mock.mock({
    'talkList|5': [
        {
            name:'@cname()',
            work:'高级售后工程师',
            content:'@cparagraph(1)'
            
        }
    ],
})
Mock.mock('/api/talkList', 'post', (config) => {

    return {
        code: 200,
        message: '获取数据成功',
        data: talkList
    }
})

let options = [
    {
        name: '技术资料',
        about: 'XXXX'
    },
    {
        name: '采购资料',
        about: 'XXXX'
    }
];
Mock.mock('/api/option', 'post', (config) => {

    return {
        code: 200,
        message: '获取数据成功',
        data: options 
    }
})
Mock.mock('/api/addoption', 'post', (config) => {
    const req = JSON.parse(config.body)
    console.log('1111111111111111111111', req);
    const newOption = {
        name: req.name,
        about: req.about
    };
    options.push(newOption);
    return {
        code: 200,
        message: '添加成功',
        data: options
    };
})
Mock.mock('/api/deloption', 'post', (config) => {
    const req = JSON.parse(config.body)
    console.log('1111111111111111111111', req);

    const newOptions = options.filter(option => option.name !== req.name);
    console.log('New Options:', newOptions);

    return {
        code: 200,
        message: '删除成功',
        data: newOptions
    };
})

